package com.llt.ai.tools;

import com.llt.ai.dto.Result;
import com.llt.ai.entity.Booking;
import com.llt.ai.service.IBookingService;
import lombok.RequiredArgsConstructor;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;
import org.springframework.stereotype.Service;

/**
 * @author LLT
 */
@Service
@RequiredArgsConstructor
public class BookingTools {

	private final IBookingService bookingService;

	@Tool(description = "查询机票信息")
	Result getBookingDetails(@ToolParam(description = "预定号") String bookingNumber,
							 @ToolParam(description = "姓名") String name) {
		try {
			Result booking = bookingService.getBookingDetail(bookingNumber, name);
			if (booking == null) {
				throw new IllegalArgumentException("未找到对应的机票信息");
			}
			return booking;
		} catch (Exception e) {
			throw new RuntimeException("查询数据库时发生异常：" + e.getMessage());
		}
	}

	@Tool(description = "取消机票预定,用户输入取消后先查询机票信息展示给用户,再让用户输入'确实'后再进行退票")
	boolean cancelBooking(@ToolParam(description = "预定号") String bookingNumber,
						  @ToolParam(description = "姓名") String name) {
		return bookingService.cancelBooking(bookingNumber, name );
	}
}
